<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Sexual_orientation_entity{
	var $current_dbprefix = "";
	var $id = 0;
	var $language_id = 0;
	var $code = 0;
	var $orientation = '';
	
	function __construct() {
		$ci= & get_instance();
		$this->current_dbprefix = $ci->db->dbprefix;
		$ci->db->set_dbprefix('default_');
	}
	function __destruct() {
		$ci= & get_instance();
		$ci->db->set_dbprefix($this->current_dbprefix);
	}
	
	function setId($input){
		$this->id=$input;
	}
	function setLanguageId($input){
		$this->language_id=$input;
	}
	function setCode($input){
		$this->code=$input;
	}
	function setOrientation($input){
		$this->orientation=$input;
	}
	
	function getId(){
		return $this->id;
	}
	function getLanguageId(){
		return $this->language_id;
	}
	function getCode(){
		return $this->code;
	}
	function getOrientation(){
		return $this->orientation;
	}
	function init($cmd, $input)
	{
		$ci=& get_instance();
		if($cmd == 'id'){
			$result = $ci->db->where('id',$input)->get(TBL_SEXUAL_ORIENTATION)->result();
		}else if($cmd == 'orientation'){
			$result = $ci->db->where('orientation',$input)->get(TBL_SEXUAL_ORIENTATION)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->language_id = $result[0]->language_id;
			$this->code = $result[0]->code;
			$this->orientation = $result[0]->orientation;
			return $this;
		}
		return false;
	}
	function getSexualOrientationByCode($code){
		$ci=& get_instance();
		$ci->db->where('code',$code);
		return $ci->db->get(TBL_SEXUAL_ORIENTATION)->result();
	}
	function getSexualOrientationList(){
		$ci=& get_instance();
		return $ci->db->get(TBL_SEXUAL_ORIENTATION)->result();
	}
	function getSexualOrientationListByLanguage($language_id){
		$ci=& get_instance();
		$ci->db->where('language_id',$language_id);
		return $ci->db->get(TBL_SEXUAL_ORIENTATION)->result();
	}
	function save(){
		$ci=& get_instance();
		$ci->db->set('language_id',$this->getLanguageId());
		$ci->db->set('code',$this->getCode());
		$ci->db->set('orientation',$this->getOrientation());
		$ci->db->insert(TBL_SEXUAL_ORIENTATION);
		return $ci->db->insert_id();
	}
	function update(){
		$ci=& get_instance();
		$ci->db->set('language_id',$this->getLanguageId());
		$ci->db->set('code',$this->getCode());
		$ci->db->set('orientation',$this->getOrientation());
		return $ci->db->where('id', $this->id)->update(TBL_SEXUAL_ORIENTATION);
	}
	function delete($id){
		$ci=& get_instance();
		$ci->db->where('id',$id);
		$ci->db->delete(TBL_SEXUAL_ORIENTATION);
	}
	function deleteByCode($code){
		$ci=& get_instance();
		$ci->db->where('code',$code);
		$ci->db->delete(TBL_SEXUAL_ORIENTATION);
		return $ci->db->affected_rows();
	}
	function checkExistedName($id, $name){
		$ci=& get_instance();
		if($id){
			$ci->db->where('id !=',$id);
		}
		$ci->db->where('orientation',$name);
		return $ci->db->get(TBL_SEXUAL_ORIENTATION)->result();
	}
}